package com.example.onlineeducation.adapter

import android.annotation.SuppressLint
import com.example.onlineeducation.R
import com.example.onlineeducation.data.constant.QuestionType
import com.example.onlineeducation.data.entity.ExamAnswerEntity
import com.example.onlineeducation.data.entity.ExamOptionEntity
import com.example.onlineeducation.databinding.ExamResultQuestionItemBinding
import com.example.onlineeducation.databinding.ExamResultQuestionOptionItemBinding
import com.yc.jetpacklib.extension.ycIsNotEmpty
import com.yc.jetpacklib.extension.ycSetTextColorRes
import com.yc.jetpacklib.recycleView.YcRecyclerViewAdapter
import com.yc.jetpacklib.utils.YcResources

/**
 * SimpleDes:
 * Creator: Sindi
 * Date: 2022-05-05
 * UseDes:
 */
class OptionsAdapter(userSelectOptionIds: List<String>?) : YcRecyclerViewAdapter<ExamOptionEntity, ExamResultQuestionOptionItemBinding>(ExamResultQuestionOptionItemBinding::inflate) {

    @SuppressLint("SetTextI18n")
    override var mOnUpdate2: (ExamResultQuestionOptionItemBinding.(position: Int, data: ExamOptionEntity) -> Unit)? = { position: Int, data: ExamOptionEntity ->
        tvContent.text = "${(position + 65).toChar()}、${data.content}"

        if (data.isAnswer == QuestionType.IS_RIGHT) {//是否正确答案,  0-错误,1-正确
            tvContent.ycSetTextColorRes(R.color.selector_box_select)
            clSelect.background = YcResources.getDrawable(R.drawable.select_box_bg_pass)
        } else if (data.isAnswer == QuestionType.IS_ERROR) {
            if (userSelectOptionIds.ycIsNotEmpty() && userSelectOptionIds!!.contains(data.id)) {
                clSelect.background = YcResources.getDrawable(R.drawable.select_box_bg_wrong)
                tvContent.ycSetTextColorRes(R.color.selector_box_select_wrong)
            } else {
                clSelect.background = YcResources.getDrawable(R.drawable.select_box_bg_default)
                tvContent.ycSetTextColorRes(R.color.selector_box_default)
            }
        } else {
            clSelect.background = YcResources.getDrawable(R.drawable.select_box_bg_default)
            tvContent.ycSetTextColorRes(R.color.selector_box_default)
        }

    }


}